const Router = require("@koa/router");
const momentRouter = new Router({ prefix: "/moment" });

const {
	create,
	list,
	detail,
	update,
	remove,
	addLabels,
	getPictureInfo
} = require("../controller/moment.controller");

// 登录校验和修改权限的中间件
const { verifyAuth, verifyPerm } = require("../middleware/auth.middleware");

// 验证标签是否存在的中间件
const { verifyLabelExists } = require("../middleware/label.middleware");
const momentRequest = require("../request/moment.request");

// 在路由中使用中间件
// 新增
momentRouter.post("/", verifyAuth, momentRequest, create);
// 列表
momentRouter.get("/", list);
// 详情
momentRouter.get("/:momentId", detail);
// 修改
momentRouter.patch("/:momentId", verifyAuth, verifyPerm, momentRequest, update);
// 删除
momentRouter.delete("/:momentId", verifyAuth, verifyPerm, remove);
// 给动态添加标签
momentRouter.post(
	"/:momentId/labels",
	verifyAuth,
	verifyPerm,
	verifyLabelExists,
	addLabels
);
// 获取内容配图
momentRouter.get("/images/:filename", getPictureInfo);

module.exports = momentRouter;
